﻿package mortal.component.window.resWin
{
    import com.gengine.resource.*;
    import mortal.game.manager.window3d.*;
    import mortal.mvc.core.*;

    public class ResView extends View implements IResWin
    {
        private var _isLoadComplete:Boolean = false;
        private var _uiRes:String;

        public function ResView(param1:String = null)
        {
            this._uiRes = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (this.hasRes)
            {
                LoaderHelp.addResCallBack(this._uiRes, this.onResLoadComplete);
            }
            else
            {
                this._isLoadComplete = true;
                this.layoutUI();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(this._uiRes, this.onResLoadComplete);
            this._isLoadComplete = false;
            return;
        }// end function

        private function onResLoadComplete() : void
        {
            this._isLoadComplete = true;
            this.layoutUI();
            this.refresh(true);
            return;
        }// end function

        public function layoutUI() : void
        {
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.refresh(true);
            return;
        }// end function

        public function display(param1:int = 0, param2:int = 0) : void
        {
            if (this.isHide)
            {
                this.show(param1, param2);
            }
            return;
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (this.allowRefresh && param1)
            {
                this.loadData();
            }
            return;
        }// end function

        protected function get allowRefresh() : Boolean
        {
            return !isHide && this.isLoadComplete;
        }// end function

        protected function loadData() : void
        {
            return;
        }// end function

        public function get isLoadComplete() : Boolean
        {
            return this._isLoadComplete;
        }// end function

        private function get hasRes() : Boolean
        {
            return this._uiRes && this._uiRes != "";
        }// end function

        public function get rect3DObject() : Rect3DObject
        {
            throw new Error("ResView 没有实现IWindow接口");
        }// end function

    }
}
